<template>
    <gui-page ref="guiPage" :customHeader="true">
        <!-- 导航 -->
        <template v-slot:gHeader>
            <nav-bar-custom left-icon="left" :leftType="'1'" @clickLeftBack="clickLeftBack"
                :title="$t('locationBarcodeInfo.crushed')" scanType="0"></nav-bar-custom>
        </template>

        <template v-slot:gBody>
            <view class="barcodeSplitting">
                <!-- 扫描和库位选择模块 -->
                <view class="custom-form-card">
                    <view class="custom-card-title">
                        <text class="title-line"></text>
                        {{ $t('hardwareOut.barcodeInformation') }}
                    </view>
                    <view class="custom-card-itemTwo" style="padding: 20rpx 0">
                        <text class="item-info-title" style="padding-right: 40rpx"><text class="required-color"
                                style="padding-right: 6rpx">*</text>{{ $t('locationBarcodeInfo.smashQty') }}：</text>
                        <uni-easyinput class="uni-mt-5" type="number" v-model="data.allInputNum">
                        </uni-easyinput>
                    </view>
                </view>
                <!-- card模块 -->
                <!-- <scroll-view :show-scrollbar="false" :scroll-y="true" class="scroll"> -->
                <!-- </scroll-view> -->
                <!-- 底部确定按钮 -->
                <view class="page-bottom-box">
                    <view class="page-bottomBtn bottomBtn-bgcolor-green" @click="handelSubmit">
                        {{ $t('calendar.submit') }}</view>
                </view>
            </view>
            <!-- 弹框填写数量 -->
            <uni-popup ref="popupInput" type="center">
                <view  class="input-dialog-box">
                    <view class="input-dialog-content">
                        <view class="gui-form-item" style="color: #dd524d">
                            <text style="width:210rpx;">{{ $t('locationBarcodeInfo.smashQty') }}：</text>
                            <view>
                                <input type="number" style="margin: 8rpx 0;" class="gui-form-input"
                                     v-model="data.allInputNum"
                                    :placeholder="$t('materials.pleaseEnterThes')" />
                            </view>
                        </view>
                    </view>
                    <view class="input-dialog-footer">
                        <view class="input-dialog-button" @click="cancelFn">
                            {{ $t('popup.cancel') }}
                        </view>
                        <view class="input-dialog-button dialog-button-left" @click="confirmFn">
                            {{ $t('popup.confirm') }}
                        </view>
                    </view>
                </view>
            </uni-popup>
        </template>
    </gui-page>
</template>

<script setup>
import { navigate, navigateBack } from '@/utils/routerSkip.js';
import superweiCombox from '@/components/superweiCombox';
import chooseSelect from '@/components/chooseSelect';
import { getDataDictionaryFn, pitchOnFn2 } from '@/utils/index.js'
import { useStore } from "vuex";  //vuex存储的数据
import pdaScan from '@/hooks/pdaScan.js'
import { basPdaOperationLogFn } from '@/utils/index.js';
import { OPERATION_COMMIT, OPERATION_LOOK, OPERATION_SCAN } from '@/constant/index.js'
import { ref, reactive, onMounted, watch, computed, toRaw } from 'vue';
import { noBarcodeOtherInCommit } from '@/api/api.js'

//JS国际化引入
import { useI18n } from 'vue-i18n';
import { onBackPress } from '@dcloudio/uni-app';
components: {
    superweiCombox,
        chooseSelect
}
const { t } = useI18n();

let store = useStore();
const { scan } = pdaScan()

//页面弹框输入数量使用的变量
let popupInput = ref(null)

let data = reactive({
    allInputNum: null,//总数量
});
onMounted(() => {
})

//提交按钮
const handelSubmit = () => {
    if (data.allInputNum == 0 || data.allInputNum == null) {
        uni.showToast({ title: t('smashRemoval.pleaseEnterQty'), icon: "none" });
        return
    }
    popupInput.value.open()

}

// 确定
const confirmFn = () => {
    if (data.allInputNum == 0 || data.allInputNum == null) {
        uni.showToast({ title: t('smashRemoval.pleaseEnterQty'), icon: "none" });
        return
    }
    let parmes = {
        changeQty: data.allInputNum
    }
    // 添加加载框
    uni.showLoading({
        title: 'loading',
        mask: true
    });
    noBarcodeOtherInCommit(parmes).then(res => { //接口
        console.log(res)
        try {
            let inputParameter = JSON.stringify(parmes)
            let returnParameter = JSON.stringify(res)
            let operationPicture = '开槽发泡板粉碎'
            let callInterface = res.rquestUrl
            let opertionParmes = {
                inputParameter,
                returnParameter,
                operationPicture,
                callInterface,
                responseCode: res.status,//返回状态
                errorMessage: res.message,//错误信息
                isPass: res.status == 200 ? 'Y' : 'N',//是否成功 Y N
                operationType: OPERATION_COMMIT
            }
            basPdaOperationLogFn(opertionParmes)
        } catch (error) {
        }
        if (res.status == 200) {
            //隐藏加载框
            uni.hideLoading();
            //删除已提交的数据
            uni.showToast({ title: t('smashRemoval.submitSuccessfully'), icon: "none" });
            data.allInputNum = null
            popupInput.value.close()
        } else {
            uni.showToast({ title: res.message, icon: "none" });
        }
    })
}


// 弹框取消
const cancelFn = () => {
    popupInput.value.close()
}

//导航栏左侧返回
const clickLeftBack = () => {
    uni.navigateBack({
        delta: 1
    });
    return
    uni.showModal({
        title: t('smashRemoval.warmPrompt'),
        content: t('materials.unsubmittedDataIn'),
        success: function (res) {
            if (res.confirm) {
                store.dispatch('hardWare/resetIqcOutScanListOther')
                uni.navigateBack({
                    delta: 1
                });
            } else if (res.cancel) {
                console.log('用户点击取消');
            }
        }
    });
}

//点击物理按键的返回
onBackPress((options) => {
    if (options.from == 'backbutton') {
        if (!data.iqcOutScanListOther.length) {
            uni.navigateBack({
                delta: 1
            });
            return true
        }
        uni.showModal({
            title: t('smashRemoval.warmPrompt'),
            content: t('materials.unsubmittedDataIn'),
            success: function (res) {
                if (res.confirm) {
                    //清除store 里面的数据
                    uni.navigateBack({
                        delta: 1
                    });
                } else if (res.cancel) {
                    // console.log('用户点击取消');
                }
            }
        });
        return true;
    }
})

</script>

<style lang="scss" scoped>
.barcodeSplitting {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 88rpx);
    // height: 100vh;
}

.distributed-head {
    border-bottom-left-radius: 16rpx;
    border-bottom-right-radius: 16rpx;
}

.scroll {
    flex: 1;
    height: 2rpx;
}

.page-bottom-box {
    position: absolute;
    left: 0rpx;
    bottom: 0rpx;
    width: 100%
}

.item-info-title {
    width: 100px !important;
}

.checkbox {
    display: flex;
    flex-direction: row;
    line-height: 100%;

    &-check {
        width: 10%;
        text-align: right;
        box-sizing: border-box;
        // margin-left: 10rpx;
    }

    &-spec {
        flex: 1;
        font-size: 28rpx;
        padding-left: 10rpx;
        line-height: 160%;
    }
}
</style>
